package gui;

import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import logic.Piece;

public class PieceGUI extends Button {

	private int x;
	private int y;
	private Piece piece;

	public PieceGUI(Piece piece) {
		this.piece = piece;

		ImageView view = new ImageView(new Image("images/"
				+ imagePieces(piece.getType(), piece.getColor())));
		this.setPadding(new Insets(0));
		this.setGraphic(view);
		this.setLayoutX(10 + (piece.getColumn() * 50));
		this.setLayoutY(10 + (piece.getRow() * 50));
		this.setStyle("-fx-background-radius: 20;-fx-background-insets: 0;");
		this.x = piece.getColumn();
		this.y = piece.getRow();
	}

	private String imagePieces(int p, int color) {
		String r = color == Piece.COLOR_GREEN ? "g" : "r";
		switch (p) {
		case Piece.TYPE_CANNON:
			r += "c.png";
			break;
		case Piece.TYPE_ELEPHANT:
			r += "e.png";
			break;
		case Piece.TYPE_GUARD:
			r += "g.png";
			break;
		case Piece.TYPE_HOURSE:
			r += "h.png";
			break;
		case Piece.TYPE_KING:
			r += "k.png";
			break;
		case Piece.TYPE_PAWN:
			r += "p.png";
			break;
		case Piece.TYPE_ROOK:
			r += "r.png";
			break;
		}
		return r;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Piece getPiece() {
		return piece;
	}

	public void setPiece(Piece piece) {
		this.piece = piece;
	}

}
